package cn.ljy.uem.service.impl;


import cn.ljy.authority.service.impl.IBaseService;
import cn.ljy.common.exception.model.MyWebException;
import cn.ljy.uem.dao.SchoolTeacherMapper;
import cn.ljy.uem.dao.SchoolTeachingTaskLessonMessageFileMapper;
import cn.ljy.uem.dao.SchoolTeachingTaskLessonMessageMapper;
import cn.ljy.uem.dao.SchoolTeachingTaskMapper;
import cn.ljy.uem.model.SchoolTeachingTaskLessonMessage;
import cn.ljy.uem.model.SchoolTeachingTaskLessonMessageFile;
import cn.ljy.uem.model.query.SchoolTeachingTaskLessonMessageFileQuery;
import cn.ljy.uem.model.query.SchoolTeachingTaskLessonMessageQuery;
import cn.ljy.uem.service.SchoolTeachingTaskLessonMessageFileService;
import cn.ljy.uem.service.SchoolTeachingTaskLessonMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;


/**
 * @description 教学任务课堂模块的业务层接口
 * @author 廖振豪
 * @date 2022-11-29
 */
@Service
@Slf4j
public class ISchoolTeachingTaskLessonMessageFileService extends IBaseService<SchoolTeachingTaskLessonMessageFile, SchoolTeachingTaskLessonMessageFileQuery> implements SchoolTeachingTaskLessonMessageFileService {

    @Autowired
    private SchoolTeachingTaskLessonMessageFileMapper mapper;

    @Override
    protected void beforeGet(Serializable id) {
        if(mapper.findById(id)==null){
            throw new MyWebException("查找失败：找不到指定记录");
        }
    }

    @Override
    protected void beforeUpdate(SchoolTeachingTaskLessonMessageFile schoolTeachingTaskLessonMessageFile) throws MyWebException {
        if(mapper.findById(schoolTeachingTaskLessonMessageFile.getId())==null){
            throw new MyWebException("编辑失败：找不到指定记录");
        }
    }

    @Override
    protected void beforeSave(SchoolTeachingTaskLessonMessageFile schoolTeachingTaskLessonMessageFile) {

    }

    @Override
    protected void beforeDelete(Serializable[] ids) {
    }


    @Override
    protected void afterGet(SchoolTeachingTaskLessonMessageFile schoolTeachingTaskLessonMessageFile) {
//        //添加教学任务关联属性
//        if (schoolTeachingTaskLesson.getTaskId() != null) {
//            //查找教学任务课堂所属教学任务
//            SchoolTeachingTask schoolTeachingTask = schoolTeachingTaskMapper.findById(schoolTeachingTaskLesson.getTaskId());
//            //赋值
//            schoolTeachingTaskLesson.setSchoolTeachingTask(schoolTeachingTask);
//        }
//        //添加教师关联属性
//        if (schoolTeachingTaskLesson.getCreator() != null) {
//            //查找教学任务课堂所属教师
//            SchoolTeacher schoolTeacher = schoolTeacherMapper.findById(schoolTeachingTaskLesson.getCreator());
//            //赋值
//            schoolTeachingTaskLesson.setSchoolTeacher(schoolTeacher);
//        }
    }

    @Override
    protected void afterFindAll(List<SchoolTeachingTaskLessonMessageFile> list) {
//        for (SchoolTeachingTaskLesson schoolTeachingTaskLesson : list) {
//            //添加教学任务关联属性
//            if (schoolTeachingTaskLesson.getTaskId() != null) {
//                //查找教学任务课堂所属教学任务
//                SchoolTeachingTask schoolTeachingTask = schoolTeachingTaskMapper.findById(schoolTeachingTaskLesson.getTaskId());
//                //赋值
//                schoolTeachingTaskLesson.setSchoolTeachingTask(schoolTeachingTask);
//            }
//
//            //添加教师关联属性
//            if (schoolTeachingTaskLesson.getCreator() != null) {
//                //查找教学任务课堂所属教师
//                SchoolTeacher schoolTeacher = schoolTeacherMapper.findById(schoolTeachingTaskLesson.getCreator());
//                //赋值
//                schoolTeachingTaskLesson.setSchoolTeacher (schoolTeacher );
//            }
//        }
    }
}
